<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>欢迎使用${setting.name}系统</title>
<#include "/admin/include/head.htm">

    <link rel="stylesheet" href="${base}/resources/admin/css/index.css" type="text/css" />
</head>
<body style="text-align:center; background:#F0F0F0; overflow:hidden;">
<div id="pageloading" style="display:block;"></div>
<div id="topmenu" class="l-topmenu">
    <div class="l-topmenu-logo">${setting.name}后台管理系统</div>

    <div class="l-topmenu-welcome">
        <span class="l-topmenu-username"></span>欢迎您  &nbsp;
       系统时间 <i class="systime">${.now}</i>


        [<a href="/">返回前台</a>]
        [<a href="javascript:f_clean()">清除缓存</a>]

    </div>
</div>
<div id="mainbody" class="l-mainbody" style="width:99.2%; margin:0 auto; margin-top:3px;" >
    <div position="left" title="主要菜单" id="mainmenu"></div>
    <div position="center" id="framecenter">
        <div tabid="home" title="我的主页">
            <iframe frameborder="0" name="home" id="home" src="${base}/admin/welcome.aspx"></iframe>
        </div>
    </div>
</div>
<script type="text/javascript">
    //几个布局的对象
    var layout, tab, accordion;
    //tabid计数器，保证tabid不会重复
    var tabidcounter = 0;
    //窗口改变时的处理函数
    function f_heightChanged(options) {
        if (tab)
            tab.addHeight(options.diff);
        if (accordion && options.middleHeight - 24 > 0)
            accordion.setHeight(options.middleHeight - 24);
    }
    //增加tab项的函数
    function f_addTab(tabid, text, url) {
        if (!tab) return;
        if (!tabid) {
            tabidcounter++;
            tabid = "tabid" + tabidcounter;
        }
        tab.addTabItem({ tabid: tabid, text: text, url: url});
    }

    function getTabById(tabid){
        if(!tabid){
            alert("tab id 为空");
            return;
        }
        var tab = $("#framecenter > .l-tab-content > .l-tab-content-item[tabid=" + tabid + "]");
        if(!tab){
            alert("tabid【" + tabid + "】 无法找到")
            return;
        }
        return tab;
    }

    function f_clean(){
        jQuery.ligerDialog.confirm('确定清除缓存吗?', function (confirm) {
            if (confirm){
                LG.ajax({
                    url: base + '/admin/celarCache.aspx',
                    loading: '正在清除中...',
                    success: function () {
                        LG.showSuccess('清除成功');
                    },
                    error: function (message) {
                        LG.showError(message);
                    }
                });
            }
        });
    }

    function changeSystem(obj){
        window.location="/admin/" + obj.value + "/index.jhtml";
    }

    //登录
    function f_login() {
        LG.login();
    }
    //修改密码
    function f_changepassword() {
        LG.changepassword();
    }
    //切换页面
    function f_switchTab(tabid){
        tab.selectTabItem(tabid);
    }
    //判断页面是否存在
    function f_isTabItemExist(tabid){
        return tab.isTabItemExist(tabid);
    }
    //关闭当前标签
    function f_closeCurrentTab(){
        tab.removeSelectedTabItem();
    }
    $(document).ready(function () {
        // 登录页面若在框架内，则关闭当前tab页
        if (self != top) {
            var win = parent || window;
            win.LG.closeCurrentTab();
            return;
        }

        //菜单初始化
        $("ul.menulist li").live('click', function () {
            var jitem = $(this);
            var tabid = jitem.attr("menuNo");
            var url = jitem.attr("url");
            if (!url) return;
            if (!tabid) {
                tabidcounter++;
                tabid = "tabid" + tabidcounter;
                jitem.attr("tabid", tabid);

                //给url附加menuno
                if (url.indexOf('?') > -1) url += "&";
                else url += "?";
                url += "MenuNo=" + jitem.attr("menuNo");
                jitem.attr("url", url);
            }

            f_addTab(tabid, $("span:first", jitem).html(), url);

        }).live('mouseover', function () {
            var jitem = $(this);
            jitem.addClass("over");
        }).live('mouseout', function () {
            var jitem = $(this);
            jitem.removeClass("over");
        });

        //布局初始化
        //layout
        layout = $("#mainbody").ligerLayout({
            height: '100%',
            heightDiff: -3,
            leftWidth: 140,
            onHeightChanged: f_heightChanged,
            minLeftWidth: 120
        });
        var bodyHeight = $(".l-layout-center:first").height();
        //Tab
        tab = $("#framecenter").ligerTab({height: bodyHeight, contextmenu: true});


        var  timestamp = parseInt(new Date('${.now}').getTime());
        //服务器时间获取
        function sysTime() {
            var d = new Date(timestamp), yyyy = d.getFullYear(), MM = d.getMonth() + 1, dd = d
                    .getDate(), hh = d.getHours(), mm = d.getMinutes(), ss = d
                    .getSeconds();
            MM = MM < 10 ? "0" + MM : MM;
            dd = dd < 10 ? "0" + dd : dd;
            hh = hh < 10 ? "0" + hh : hh;
            mm = mm < 10 ? "0" + mm : mm;
            ss = ss < 10 ? "0" + ss : ss;
            $(".systime").html([ yyyy, "-", MM, "-", dd, " ", hh, ":", mm, ":", ss ].join(""));
            timestamp = timestamp + 1000;
        }

        //预加载dialog的背景图片
        LG.prevDialogImage();
        var mainmenu = $("#mainmenu");
        $.getJSON(base + '/admin/menu/getLeftMenu.aspx?data=' + Math.random(), function (menus) {
            var menus = assemblyTreeObj(menus);
            $(menus).each(function (i, menu) {
                var item = $('<div title="' + menu.name + '"><ul class="menulist"></ul></div>');
                $(menu.childs).each(function (j, submenu) {
                    var subitem = $('<li><img/><span></span><div class="menuitem-l"></div><div class="menuitem-r"></div></li>');
                    var url = base + submenu.url;
                    subitem.attr({
                        url: url,
                        tabid: submenu.id,
                        menuno: submenu.menuNo
                    });
                    if (!submenu.menuIcon) {
                        $("img", subitem).attr("src", base + "/resources/admin/images/icons/32X32/my_account.gif");
                    } else {
                        $("img", subitem).attr("src", base + "/resources/admin/images/icons/32X32/" + submenu.moduleIcon);
                    }

                    $("span", subitem).html(submenu.name);
                    $("ul:first", item).append(subitem);
                });

                mainmenu.append(item);
            });
            timestamp = parseInt(new Date('${.now}').getTime());
            sysTime();
            setInterval(function() {sysTime();}, 1000);
            //Accordion
            accordion = mainmenu.ligerAccordion({
                height: bodyHeight - 24,
                speed: null
            });
            $("#pageloading").hide();
        });
    });


</script>
</body>
</html>